package com.pingan.agentbank.aaos.testme;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class JdbcTest {

    @Test
    public void method1(){

        InputStream inputStream = ClassLoader.getSystemResourceAsStream("uccb_jdbc.properties");
        Properties prop = new Properties();
        try {
            prop.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            Class.forName(prop.getProperty("driver"));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(prop.getProperty("url"),prop.getProperty("name"),prop.getProperty("password"));
        } catch (SQLException e) {
            e.printStackTrace();
        }

        try{

            String sql = "update appro_file set state = 1";
            PreparedStatement stat = connection.prepareStatement(sql);
            stat.executeUpdate();

            /*String sql1 = "delete from appro_line";
            PreparedStatement stat1 = connection.prepareStatement(sql1);

            //String sql = "update appro_file set state = 4";
            //PreparedStatement stat = connection.prepareStatement(sql);

            stat1.executeUpdate();*/
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }

    @Test
    public void method2(){

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/aaos_platform?characterEncoding=utf8&useSSL=false","root","root123");
        } catch (SQLException e) {
            e.printStackTrace();
        }

        String sql = "select version()";
        Statement statement = null;
        try {
            statement = connection.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
                String version = rs.getString("version()");
                System.out.println("mysql version: "+version);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void method3(){

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection connection = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/aaos_platform_uccb?characterEncoding=utf8&useSSL=false","root","root123");
        } catch (SQLException e) {
            e.printStackTrace();
        }

        String sql = "select * from appro_abnormal";
        Statement statement = null;
        try {
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){
                int id = resultSet.getInt(1);
                System.out.println(id);
            }

            /*statement.execute(sql);
            System.out.println(statement.getUpdateCount());*/

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
